package cn.damai.mine.collectArraySort;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class CollectArraySort {

	public static void main(String[] args) {

		String[] players = { "Rafael Nadal", "Novak Djokovic",
				"Stanislas Wawrinka", "David Ferrer", "Roger Federer",
				"Andy Murray", "Tomas Berdych", "Juan Martin Del Potro",
				"Richard Gasquet", "John Isner" };

		// 1.1 使用匿名内部类根据 name 排序 players
		Arrays.sort(players, new Comparator<String>() {
			@Override
			public int compare(String s1, String s2) {
				return (s1.compareTo(s2));
			}
		});
		
		List<String> list = Arrays.asList(players);
		list.forEach(e->System.out.println(e));
		
		Collections.sort(list, new Comparator<String>() {

			@Override
			public int compare(String o1, String o2) {
				// TODO Auto-generated method stub
				
				//如果按照对象的某个属性比较  按照对象属性的属性定义变量 进行变量比较
				/*Double valA = 0d;
	            Double valB = 0d;

	            try {
	                valA = Double.valueOf(o1.get属性);
	                valB = Double.valueOf(o2.get属性);
	            } 
	            catch (JSONException e) {
	                //do something
	            }
	            return valA.compareTo(valB);*/
				
				return (o1.compareTo(o2));
			}
		});
		

	}

}
